<?php
require_once 'Junction/Db/Creole/Adapter.php';
require_once 'Test/Database/Catalog.php';

class Test_Junction_Db_Creole_Adapter extends PHPUnit_Framework_TestCase {

	private static $_validMySQL = array(
			'db_driver' => 'mysql',
			'db_host' => 'localhost',
			'db_name' => 'JunctionTest',
			'db_user' => 'JunctionUser',
			'db_pass' => 'junction');
			
	private static $_invalidMySQL = array(
			'db_driver' => 'mysql',
			'db_host' => 'localhost',
			'db_name' => 'NotADatabase!!',
			'db_user' => 'JunctionUser',
			'db_pass' => 'junction');
			
	private static $_validSqlite;
	
	public function __construct() {
		self::$_validSqlite = array(
			'db_driver' => 'sqlite',
			'db_host' => '',
			'db_name' => Test_Database_Catalog::fetch('test.sdb'),
			'db_user' => '',
			'db_pass' => '');
	}
	
	public function testMySQL() {
		try {
			$adapter = new Junction_Db_Creole_Adapter();
			$adapter->connectTo(self::$_validMySQL);
				
			$dao = $adapter->getConnection();
			$this->assertTrue(isset($dao));
		} catch (Junction_Db_Exception $e) {
			$this->fail();
		}
		
		try {
			$adapter = new Junction_Db_Creole_Adapter();
			$adapter->connectTo(self::$_invalidMySQL);
			$this->fail();
		} catch (Junction_Db_Exception $e) {
			$this->assertTrue(true);
		} catch (Exception $e) {
			$this->fail();
		}
	}
	
	public function testSqlite() {
		try {
			$adapter = new Junction_Db_Creole_Adapter();
			$adapter->connectTo(self::$_validSqlite);
				
			$dao = $adapter->getConnection();
			$this->assertTrue(isset($dao));
			
		} catch (Junction_Db_Exception $e) {
			$this->fail();
		}
	}
}
?>